package com.tiger.cloud.controller.crm;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tiger.cloud.common.mybatis.BaseController;
import com.tiger.cloud.form.RegionsForm;
import com.tiger.cloud.service.system.CommonRegions;
import com.tiger.cloud.util.Response;
import com.tiger.cloud.util.ResponseUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 区域表
 */
@Controller
@RequestMapping(value = "regions")
@Api(value = "省市区地区",tags = "区域")
public class RegionsController extends BaseController {

	private static final Logger logger=Logger.getLogger(RegionsController.class);
	
	/**
	 * 获取省市区三级联动列表
	 * @param regionsForm
	 * @return
	 */
	@RequestMapping(value = "get", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "获取省市区三级联动列表",notes = "获取省市区三级联动列表")
	public Response list(@RequestBody RegionsForm regionsForm){
		if(regionsForm.getType()==2 && regionsForm.getpRegionId()!=null){//市
			return ResponseUtil.ok(CommonRegions.getCitys(regionsForm.getpRegionId()));
		}else if(regionsForm.getType()==3 && regionsForm.getpRegionId()!=null){//区
			return ResponseUtil.ok(CommonRegions.getDistricts(regionsForm.getpRegionId()));
		}
		return ResponseUtil.ok(CommonRegions.getProvices());//省
	}
	
	
	

}